
****************************************************************;
** Select a subset of 2006 denominator files with hedis match **;
****************************************************************;

options ls=76 nofmterr;

libname raw '/data/Medicare_P01_2009/data/HEDIS/rawdata';
libname new '/data/Medicare_P01_2009/data/HEDIS/sasdata';


     data xwalk00; set raw.hic_bene_xwalk_2006;

         if hic_match=1;
         if bene_id=' ' then delete;

         length hic_number $ 12;
         hic_number=orig_hic;

         proc sort; by hic_number;


    data xwalk0; set xwalk00;

         proc freq data=xwalk0 noprint;
              tables hic_number/out=benecnt;

         proc freq data=benecnt;
              tables count;
              title 'HEDIS2006: Num of BENE links for one HIC number';

    data xwalk(drop=count); merge xwalk00 benecnt; by hic_number;

         if count=1; /** only keep cases with one unique BENE ID **/

         keep hic_match hic_number bene_id count;

         proc sort; by bene_id;

data denom; set raw.denom2006;

     denom_flag=1;
     
     sex  = 1*BENE_SEX_IDENT_CD;
     race = 1*BENE_RACE_CD;          
     age  = BENE_AGE_AT_BEG_REF_YR;

     length racec gender agec $ 10;

     if race=1 then racec='1.White';
     if race=2 then racec='2.Black';
     if race=3 then racec='3.Other';
     if race=4 then racec='4.Asian';
     if race=5 then racec='5.Hispanic';
     if race=6 then racec='6.Native';
     if race=. then racec='0.Unknown';

     if sex=1 then gender='1.Male';
     if sex=2 then gender='2.Female';

     if age>0   and age<20 then agec='1-20 yr';
     if age>=20 and age<30 then agec='20-29 yrs';
     if age>=30 and age<40 then agec='30-39 yrs';
     if age>=40 and age<50 then agec='40-49 yrs';
     if age>=50 and age<60 then agec='50-59 yrs';
     if age>=60 and age<65 then agec='60-64 yrs';
     if age>=65 and age<70 then agec='65-69 yrs';
     if age>=70 and age<75 then agec='70-74 yrs';
     if age>=75 and age<80 then agec='75-79 yrs';
     if age>=80 and age<85 then agec='80-84 yrs';
     if age>=85            then agec='85+';

     proc sort; by bene_id;

data new.hedis06denom; merge xwalk denom; by bene_id;

     if hic_match=1;
     
     proc contents data=new.hedis06denom varnum;
          title 'HEDIS2006 matched denom dataset';
        
endsas;





